package webServices;

import javax.jws.*;
import javax.jws.soap.*;

import cern.jet.random.Poisson;
import cern.jet.random.engine.MersenneTwister;

@WebService(targetNamespace = "http://www.operations.com/", serviceName = "Arithmetic Operations")
@SOAPBinding(style = SOAPBinding.Style.RPC)  
@HandlerChain(file = "../../META-INF/jaxws-handlers-server.xml")
public class Operations {
	private static final double MRT_SUBSTRACTION=1000.0;
	private static final double MRT_ADDITION=100.0;
	private Poisson p_substraction=null;
	private Poisson p_addition=null;
	
	@WebMethod
	@WebResult(name="result")
	public int addition(@WebParam(name="sequence_number",header=true) int sequence_number, 
						@WebParam(name="username",header=true) String username, 
						@WebParam(name="password",header=true) String password,
			@WebParam(name="number1") int number1, 
			 @WebParam(name="number2") int number2){
		if(p_addition==null)
			p_addition = new Poisson(MRT_ADDITION, new MersenneTwister());
		try {
			int num=p_addition.nextInt();
			System.out.println(num);
			Thread.sleep(num);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return number1 + number2;
	}
	
	@WebMethod
	@WebResult(name="result")
	public int substraction(@WebParam(name="sequence_number",header=true) int sequence_number, 
							@WebParam(name="username",header=true) String username, 
							@WebParam(name="password",header=true) String password,
							int number1, 
							@WebParam(name="number2") int number2){
		if(p_substraction==null)
			p_substraction = new Poisson(MRT_SUBSTRACTION, new MersenneTwister());
		try {
			int num=p_substraction.nextInt();
			System.out.println(num);
			Thread.sleep(num);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return number1 - number2;
	}
}
